package com.rr.graphql.dataloader;

import com.netflix.graphql.dgs.DgsDataLoader;
import com.rr.dto.Employee;
import com.rr.graphql.resolver.EmployeeQueryResolver;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dataloader.BatchLoader;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

/**
 * @author RR
 * @date 2023/6/23 23:00
 */
@DgsDataLoader(name = "employees")
@AllArgsConstructor
@Slf4j
public class EmployeeDataLoader implements BatchLoader<String, List<Employee>> {

    private EmployeeQueryResolver employeeQueryResolver;

    @Override
    public CompletionStage<List<List<Employee>>> load(List<String> departmentIds) {
        return CompletableFuture.supplyAsync(() -> employeeQueryResolver.employeeQueryByDepartmentIds(departmentIds));
    }
}
